<script runat="server" language="jscript">
	asplib.file = {
	
		fileExists : function(filePath) {
			var fso = new ActiveXObject("Scripting.FileSystemObject");
			return fso.FileExists( Server.MapPath(filePath) );
		},
		
		folderExists : function(folderPath) {
			parameters_base = folderPath;
			if (parameters_base.length != 1) {
				search_path_have_backslash = parameters_base.substr(parameters_base.length - 1, 1) == "/";
				search_path_have_slash	   = parameters_base.substr(parameters_base.length - 1, 1) == "\\";
				
				if (search_path_have_backslash || search_path_have_slash) {
					parameters_base = parameters_base.substr(0, parameters_base.length - 1);
				}
			}
			
			if (!new ActiveXObject("Scripting.FileSystemObject").FolderExists(Server.MapPath(parameters_base))) {
				return false;
			} else {
				return parameters_base;
			}
		},
		
		readAllText : function (filePath) {

			try {
				var stream = Server.CreateObject("ADODB.Stream");
			} catch (e) {
				throw e;
			}
			
			stream.type = 2;
			stream.mode = 3;
			stream.open();
			
			try {
				if (arguments[1] == false) {
					stream.loadFromFile( Server.MapPath(filePath) );
				} else {
					stream.loadFromFile( filePath );
				}
			} catch (e) {
				throw e;
			}
			
			stream.charset 	= ( arguments[2] == null ) ? "gb2312" : arguments[2];
			stream.position = 2;
			return stream.readText();
			stream.close();
			stream = null;
			
		},
		
		writeText : function (filePath, content) {

			try {
				var stream = Server.CreateObject("ADODB.Stream");
			} catch (e) {
				throw e;
			}
			
			stream.type = 2;
			stream.open();
			
			
			stream.charset 	= ( arguments[2] == null ) ? "gb2312" : arguments[2];
			stream.position = stream.size;
			stream.writeText = content;
			stream.saveToFile( Server.MapPath(filePath), 2 );
			stream.close();
			stream = null;
			
		}
	}
</script>